@extends('shop::layouts.master')
@section('title')
    检车站规格列表
@endsection
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">

                    <div class="layui-card-body">
                        <button class="layui-btn layui-btn-normal" onclick="xadmin.open('添加检车站规格','{{route("shop_check_specs_create")}}',800,600)"><i class="layui-icon"></i>添加规格</button>
                        <a class="layui-btn" onclick="location.reload()">
                            <i class="layui-icon layui-icon-refresh"></i>
                        </a>
                    </div>
                    <div class="layui-card-body layui_overflow_y">

                        <table class="layui-table layui-form">
                            <thead>
                            <tr>
                                <th>序号</th>
                                <th>ID</th>
                                <th>规格名称</th>
                                <th>规格参数</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            @foreach($arr_data as $key=>$value)

                                <tr>
                                    <td>{{$key+1}}</td>
                                    <td>{{$value["id"]}}</td>
                                    <td>{{$value["name"]}}</td>
                                    <td>

                                        @if(!empty($value['_child']))
                                            <table class="layui-table layui-form">
                                                <thead>
                                                <tr>
                                                    {{--                                                <th>序号</th>--}}
                                                    {{--                                                <th>ID</th>--}}
                                                    <th>参数</th>
                                                    <th>价格</th>
                                                    <th>操作</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                @foreach($value['_child'] as $kk=>$vv)

                                                    <tr>
                                                        {{--                                                    <td>{{$kk+1}}</td>--}}
                                                        {{--                                                    <td>{{$vv["id"]}}</td>--}}
                                                        <td>{{$vv["name"]}}</td>
                                                        <td>{{$vv["price"]}}</td>
                                                        <td class="td-manage">
                                                            @if($vv["is_goto_use"] == 1)
                                                                <input type="checkbox" name="switch" data_attr='{"id":"{{$vv['id']}}","field_name":"is_goto_use","url":"{{route("shop_check_specs_change_state")}}"}'  lay-text="到站使用|到站禁用" lay-filter="change_state" checked="" lay-skin="switch">
                                                            @else
                                                                <input type="checkbox" name="switch" data_attr='{"id":"{{$vv['id']}}","field_name":"is_goto_use","url":"{{route("shop_check_specs_change_state")}}"}' lay-text="到站使用|到站禁用" lay-filter="change_state" lay-skin="switch">
                                                            @endif

                                                            @if($vv["is_driving_use"] == 1)
                                                                <input type="checkbox" name="switch" data_attr='{"id":"{{$vv['id']}}","field_name":"is_driving_use","url":"{{route("shop_check_specs_change_state")}}"}'  lay-text="代驾使用|代驾禁用" lay-filter="change_state" checked="" lay-skin="switch">
                                                            @else
                                                                <input type="checkbox" name="switch" data_attr='{"id":"{{$vv['id']}}","field_name":"is_driving_use","url":"{{route("shop_check_specs_change_state")}}"}' lay-text="代驾使用|代驾禁用" lay-filter="change_state" lay-skin="switch">
                                                            @endif
                                                            <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('修改参数','{{route("shop_check_specs_edit",["id"=>$vv["id"]])}}')" ><i class="layui-icon">&#xe642;</i>修改</button>
                                                            <button class="layui-btn-danger layui-btn layui-btn-xs ajax_member_del" data-href="{{route('shop_check_specs_delete',['id'=>$vv['id']])}}" data-title="确定删除参数吗？请谨慎操作" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                                        </td>
                                                    </tr>

                                                @endforeach
                                                </tbody>
                                            </table>

                                        @else
                                            无

                                        @endif



                                    </td>
                                    <td class="td-manage">
                                        @if($value["pid"] === 0)
                                            <button class="layui-btn layui-btn-normal"  onclick="xadmin.open('添加规格参数','{{route("shop_check_specs_params_create",["id"=>$value["id"]])}}')" ><i class="layui-icon"></i>添加规格参数</button>
                                        @endif

                                            @if($value["is_goto_use"] == 1)
                                                <input type="checkbox" name="switch" data_attr='{"id":"{{$value['id']}}","field_name":"is_goto_use","url":"{{route("shop_check_specs_change_state")}}"}'  lay-text="到站使用|到站禁用" lay-filter="change_state" checked="" lay-skin="switch">
                                            @else
                                                <input type="checkbox" name="switch" data_attr='{"id":"{{$value['id']}}","field_name":"is_goto_use","url":"{{route("shop_check_specs_change_state")}}"}' lay-text="到站使用|到站禁用" lay-filter="change_state" lay-skin="switch">
                                            @endif

                                            @if($value["is_driving_use"] == 1)
                                                <input type="checkbox" name="switch" data_attr='{"id":"{{$value['id']}}","field_name":"is_driving_use","url":"{{route("shop_check_specs_change_state")}}"}'  lay-text="代驾使用|代驾禁用" lay-filter="change_state" checked="" lay-skin="switch">
                                            @else
                                                <input type="checkbox" name="switch" data_attr='{"id":"{{$value['id']}}","field_name":"is_driving_use","url":"{{route("shop_check_specs_change_state")}}"}' lay-text="代驾使用|代驾禁用" lay-filter="change_state" lay-skin="switch">
                                            @endif
                                        <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('修改规格','{{route("shop_check_specs_edit",["id"=>$value["id"]])}}')" ><i class="layui-icon">&#xe642;</i>修改</button>
                                        <button class="layui-btn-danger layui-btn layui-btn-xs ajax_member_del" data-href="{{route('shop_check_specs_delete',['id'=>$value['id']])}}" data-title="确定删除规格吗？请谨慎操作" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                    </td>
                                </tr>

                            @endforeach
                            @if(count($arr_data) == 0)
                                <tr>
                                    <td colspan="66" style="text-align: center">暂无数据</td>

                                </tr>

                            @endif
                            </tbody>
                        </table>
                    </div>
           {{--         <div class="layui-card-body ">
                        <div class="page">
                            {{$page_link}}
                        </div>

                        --}}{{--     <div class="page">
                                 <div>
                                     <a class="prev" href="">&lt;&lt;</a>
                                     <a class="num" href="">1</a>
                                     <span class="current">2</span>
                                     <a class="num" href="">3</a>
                                     <a class="num" href="">489</a>
                                     <a class="next" href="">&gt;&gt;</a></div>
                             </div>--}}{{--
                    </div>--}}
                </div>
            </div>
        </div>
    </div>
@endsection

@section('tab_js')
    <script>
        layui.use(['form'], function(){
            var form = layui.form;

            //监听指定开关-修改状态
            form.on('switch(change_state)',
                function(obj){
                    change_state(this);
                    // layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                    //     offset: '60px'
                    // });
                    // layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', obj.othis)
                });

            // 分类展开收起的分类的逻辑
            //
            $(function(){
                $("tbody.x-cate tr[fid!='0']").hide();
                // 栏目多级显示效果
                $('.x-show').click(function () {
                    if($(this).attr('status')=='true'){
                        $(this).html('&#xe625;');
                        $(this).attr('status','false');
                        cateId = $(this).parents('tr').attr('cate-id');
                        $("tbody tr[fid="+cateId+"]").show();
                    }else{
                        cateIds = [];
                        $(this).html('&#xe623;');
                        $(this).attr('status','true');
                        cateId = $(this).parents('tr').attr('cate-id');
                        getCateId(cateId);
                        for (var i in cateIds) {
                            $("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe623;').attr('status','true');
                        }
                    }
                })
            });

            var cateIds = [];
            function getCateId(cateId) {
                $("tbody tr[fid="+cateId+"]").each(function(index, el) {
                    id = $(el).attr('cate-id');
                    cateIds.push(id);
                    getCateId(id);
                });
            }
        });
    </script>
@endsection




